package com.zq.it.dao.impl.admin;

import java.util.Collection;
import java.util.List;

import com.zq.it.dao.admin.MessageDao;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.Message;

public class MessageDaoImpl extends BaseDao<Message> implements MessageDao {

	@Override
	public void saveMessage(Message message) {
	
			getHibernateTemplate().save(message);		
	}

	@Override
	public void deleteMessage(Message msg){		
			getHibernateTemplate().delete(msg);
		
	}
	public List findMsgByHql(String hql){
	return getHibernateTemplate().find(hql);
	}
	@Override
	public void deleteMessageByName(String title){
//			getHibernateTemplate()
	}

	@Override
	public Message findMessageById(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List findMessageByTitle(String title){
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from Message as msg where msg.title like ?","%"+title+"%");
	}
	
 
	@Override
	public void updateMessage(Message msg){
		this.getHibernateTemplate().update(msg);
		// TODO Auto-generated method stub		
	}

	@Override
	public List<Message> getMessageListByType(String type){
	// TODO Auto-generated method stub
		return getHibernateTemplate().find("from Message as msg where msg.type=?",Integer.parseInt(type));
	}
	
	@Override
	public List<Message> findAllMessages() {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from Message");
	}

	@Override
	public List findMessageByDate(String date) {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from Message as msg where msg.updateTime=?",date);
	}

	@Override
	public void deleteMessageByGroups(Collection<Message> collection){
		getHibernateTemplate().deleteAll(collection);
		
		// TODO Auto-generated method stub	
	}
	public void saveMessageList(List list){	
		getHibernateTemplate().saveOrUpdateAll(list);	
	}
	
	public Message findByMsgEntity(Message msgEntity){
		List list=getHibernateTemplate().findByExample(msgEntity);
		return (Message)(list.size()>0 ? list.get(0):null);
	}

	@Override
	public Message findMessageByFullTitle(String title) {
		List list=getHibernateTemplate().find("from Message as msg where msg.title=?",title);
  	//	System.out.println(list.size());
		// TODO Auto-generated method stub
		return (Message)(list.size()>0?list.get(0):null);
	}
	
}
